package com.adou.d8.thread.safe;

public class Account {
    private String cardId;
    private double money;//余额

    public Account(){}
    public Account(String cardId, double money) {
        this.cardId = cardId;
        this.money = money;
    }

    // 取钱
    public void drawMoney(double money) {
        String name = Thread.currentThread().getName();
        // 1.判断余额是否足够
        if(this.money >= money) {
            System.out.println(name + "来取钱，" + money + "成功");
            this.money -= money;
            System.out.println("剩余余额：" + this.money);

        } else {
            System.out.println(name + "来取钱，余额不足");
        }
    }


    public String getCardId() {
        return cardId;
    }

    public void setCardId(String cardId) {
        this.cardId = cardId;
    }

    public double getMoney() {
        return money;
    }

    public void setMoney(double money) {
        this.money = money;
    }

    @Override
    public String toString() {
        return "Account{" +
                "cardId='" + cardId + '\'' +
                ", money=" + money +
                '}';
    }
}
